package com.example.yiwei.crm.view.activity.JYCoordingActivity;

import android.content.Intent;
import android.graphics.Color;
import android.support.annotation.ColorRes;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;

import com.bigkoo.pickerview.TimePickerView;
import com.example.yiwei.crm.R;
import com.example.yiwei.crm.view.activity.jdjycooractivity.JDJYCoorActivity;
import com.example.yiwei.crm.view.activity.jtCustomer.JDcoorActivity;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;


public class JYSearchSHActivity extends AppCompatActivity {
    private ImageView img_search,img_luru,img_me,img_tj,img_back;
    private EditText edit_name,edit_jd;
    private TimePickerView mpv1;
    Date date1,date2;
    private TimePickerView mpv2;
    private Button btn1,btn2;
    String stime;
    String etime;
    String stime1;
    String etime1;
    private TextView txt_create1,txt_create2;
    private LinearLayout linearLayout;
    private TextView txt_luru,txt_cx;
    private ImageView img_qk,img_qk1;
    private Button btn_commit;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_jysearch_sh);
        img_qk= (ImageView) findViewById(R.id.qingkong);
        btn_commit = (Button) findViewById(R.id.btn_commit);
        img_qk1= (ImageView) findViewById(R.id.qingkong1);
        img_search= (ImageView) findViewById(R.id.item_image_cx);
        linearLayout = (LinearLayout) findViewById(R.id.add_coor_linear_find);
        img_luru= (ImageView) findViewById(R.id.item_image_lr);
        img_tj= (ImageView) findViewById(R.id.item_image_tj);
        img_me= (ImageView) findViewById(R.id.item_image_w);
        txt_luru= (TextView) findViewById(R.id.item_textview_lr);
        txt_cx= (TextView) findViewById(R.id.item_textview_cx);
        img_back= (ImageView) findViewById(R.id.search_jd_img_back);
        edit_name= (EditText) findViewById(R.id.JY_manyidu_search_edit_customer_name);
        edit_jd= (EditText) findViewById(R.id.JY_manyidu_search_edit_jd_name);
        btn1= (Button) findViewById(R.id.JY_customer_search_btn_show1);
        btn2= (Button) findViewById(R.id.JY_customer_search_btn_show2);
        txt_create1= (TextView) findViewById(R.id.JY_customer_search_txt_create_time1);
        txt_create2= (TextView) findViewById(R.id.JY_customer_search_txt_create_time2);
        img_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        if ("k6".equals(getIntent().getStringExtra("tag6"))||"jd".equals(getIntent().getStringExtra("tag"))){
            img_luru.setImageResource(R.drawable.gongzuotai);
            txt_luru.setTextColor(Color.rgb(167,167,167));
            img_search.setImageResource(R.drawable.find2);
            txt_cx.setTextColor(Color.rgb(110,184,239));
        }
        //创建选择器
        mpv1 = new TimePickerView(this, TimePickerView.Type.YEAR_MONTH_DAY);
        //设置时间范围
        Calendar calendar = Calendar.getInstance();
        mpv1.setRange(calendar.get(Calendar.YEAR) - 100, calendar.get(Calendar.YEAR) + 100);
        //插入时间
        mpv1.setTime(new Date());
        //选择监听
        mpv1.setOnTimeSelectListener(new TimePickerView.OnTimeSelectListener() {

            @Override
            public void onTimeSelect(Date date) {
                date1 = date;
                stime=getTime(date);
                txt_create1.setText(stime);
            }
        });
        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mpv1.show();
            }
        });
        mpv2 = new TimePickerView(this, TimePickerView.Type.YEAR_MONTH_DAY);
        //设置时间范围
        Calendar calendar1 = Calendar.getInstance();
        mpv2.setRange(calendar1.get(Calendar.YEAR) - 100, calendar1.get(Calendar.YEAR) + 100);
        //插入时间
        mpv2.setTime(new Date());
        //选择监听
        mpv2.setOnTimeSelectListener(new TimePickerView.OnTimeSelectListener() {

            @Override
            public void onTimeSelect(Date date) {
                date2 = date;
                etime=getTime(date);
                txt_create2.setText(etime);
            }
        });
        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mpv2.show();
            }
        });
        img_qk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                txt_create1.setText("");
            }
        });
        img_qk1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                txt_create2.setText("");
            }
        });
        img_search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                    Intent intent=new Intent(JYSearchSHActivity.this,JDcoorActivity.class);
                    intent.putExtra("ii","ii");
                    startActivity(intent);
                    finish();


            }
        });
        img_luru.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if ("jd".equals(getIntent().getStringExtra("tag"))){
                    Intent intent=new Intent(JYSearchSHActivity.this,JDJYCoorActivity.class);
                    startActivity(intent);
                    finish();
                }else {
                    Intent intent=new Intent(JYSearchSHActivity.this,JDcoorActivity.class);
                    startActivity(intent);
                    finish();
                }

            }
        });
        img_me.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if ("jd".equals(getIntent().getStringExtra("tag"))){
                    Intent intent=new Intent(JYSearchSHActivity.this,JDJYCoorActivity.class);
                    intent.putExtra("me","me");
                    startActivity(intent);
                    finish();
                }else {
                    Intent intent=new Intent(JYSearchSHActivity.this,JDcoorActivity.class);
                    intent.putExtra("me","me");
                    startActivity(intent);
                    finish();
                }
            }
        });
        if ("jd".equals(getIntent().getStringExtra("tag"))){
            linearLayout.setVisibility(View.GONE);
            img_back.setVisibility(View.GONE);
        }else {
            img_back.setVisibility(View.VISIBLE);
        }
        img_tj.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(JYSearchSHActivity.this,JDcoorActivity.class);
                intent.putExtra("tt","tt");
                startActivity(intent);
                finish();
            }
        });
        btn_commit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(JYSearchSHActivity.this,JYSimpleSHActivity.class);
                intent.putExtra("KAA02",edit_name.getText().toString());
                intent.putExtra("KMA12",edit_jd.getText().toString());
                intent.putExtra("CTS0101",txt_create1.getText().toString());
                intent.putExtra("CTS0102",txt_create2.getText().toString());
                    intent.putExtra("tag6","k6");

                startActivity(intent);
                finish();
            }
        });
    }
    public static String getTime(Date date) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        return format.format(date);
    }
}
